﻿
@{
    ViewData["Title"] = "用户设置";
}

<div class="row">
    <div style="height:50px;"></div>
    <div class="col-md-12">
        <form id="ajaxForm" class="form-inline text-center" role="form">
            <div class="form-group">
                <label for="nick-name">昵称:</label>
                <input type="text" id="nick-name" name="nick_name" class="form-control" placeholder="请输入昵称" maxlength="10"/>
            </div>
            <div class="form-group">
                <button type="button" class="btn btn-xs btn-primary form-control btn-save">保存昵称</button>
            </div>
        </form>
    </div>
    <div style="height:100px;"></div>
</div>

@section Scripts{ 
    <script type="text/javascript">
        $(".btn-save").click(function () {
            if ($("#nick-name").val().length < 2) {
                alert("昵称最少为2位字符");
                return;
            }
            $.ajax({
                type: "post",
                url: "@Url.Action("UpdateUser", "Account")",
                data: $("#ajaxForm").serialize(),
                error: function (request) {
                    alert(request.data);
                },
                success: function (res) {
                    if (res.msg == 'ok') {
                        location.href = '/';
                    } else if (res.msg == 'fail') {
                        alert(res.data);
                    }
                }
            });
        });
    </script>
}